package com.bdqn.daoimpl;

import java.util.List;

import com.bdqn.dao.BaseDao;
import com.bdqn.dao.UserDao;
import com.bdqn.entity.Msguserinfo;

public class UserDaoImpl  extends  BaseDao implements UserDao {

	@Override
	public int insertUser(Msguserinfo user) {
		return super.saveObj(user);
	}

	@Override
	public Msguserinfo selectLoginUser(Msguserinfo user) {
		String sql="select  *  from  Msguserinfo  where  username=?  and  password=?";
		List<Msguserinfo>  list=super.selectList(sql, new Object[]{user.getUsername(),user.getPassword()}, Msguserinfo.class);
		return list.size()>0?list.get(0):null;
	}

	@Override
	public int updateUserActiveEamil(Msguserinfo user) {
	String  sql="update  Msguserinfo  set  avticeEmail=1  where username=?";
		return super.executeUpdate(sql,new Object[]{user.getUsername()} );
	}

	@Override
	public int selectUserEamil(Msguserinfo user) {
		String  sql="select  count(0)  from  Msguserinfo  where  username=?  and email=?";
		Long  num=(Long) super.selectOne(sql, new Object[]{user.getUsername(),user.getEmail()});
		return Integer.valueOf(num.toString()) ;
	}

	
	@Override
	public int updatePass(String username, String email, String newPass) {
		String  sql="update  Msguserinfo set  password=?  where username=? and email=? ";
		return super.executeUpdate(sql, new Object[]{newPass,username,email});
	}

	@Override
	public int updateUserPhoto(Msguserinfo user) {
		String  sql="update Msguserinfo  set  photo=?  where  username=?";
		return super.executeUpdate(sql, new Object[]{user.getPhoto(),user.getUsername()});
	}

}
